package kr.totalcall.util
{
	/**
	 * 작업 기록
	 * 2012. 6. 12. / 이규광 / 최초 작성.
	 */
	/**
	 * 내용.
	 * @productversion Flex 4.5
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 10.2
	 * @author 이규광.
	 */
	public class GPS
	{
		
		/**
		 * 거리 측정
		 */
		public static function distance(P1_latitude:Number/*C10*/, P1_longitude:Number/*C11*/, P2_latitude:Number/*C12*/, P2_longitude:Number/*C13*/):Number
		{
			if ((P1_latitude == P2_latitude)&&(P1_longitude == P2_longitude))
			{
				return 0;
			}
			
			var e10:Number = P1_latitude * Math.PI / 180;
			var e11:Number = P1_longitude * Math.PI / 180;
			var e12:Number = P2_latitude * Math.PI / 180;
			var e13:Number = P2_longitude * Math.PI / 180;
			
			/* 타원체 GRS80 */
			var c16:Number = 6356752.314140910;
			var c15:Number = 6378137.000000000;
			var c17:Number = 0.0033528107;
			
			
			var f15:Number = c17 + c17 * c17;
			var f16:Number = f15 / 2;
			var f17:Number = c17 * c17 / 2;
			var f18:Number = c17 * c17 / 8;
			var f19:Number = c17 * c17 / 16;
			
			var c18:Number = e13 - e11;
			var c20:Number = (1 - c17) * Math.tan(e10);
			var c21:Number = Math.atan(c20);
			var c22:Number = Math.sin(c21);
			var c23:Number = Math.cos(c21);
			var c24:Number = (1 - c17) * Math.tan(e12); 
			var c25:Number = Math.atan(c24);
			var c26:Number = Math.sin(c25);
			var c27:Number = Math.cos(c25);
			
			var c29:Number = c18;
			var c31:Number = (c27 * Math.sin(c29) * c27 * Math.sin(c29)) + (c23 * c26 - c22 * c27 * Math.cos(c29)) * (c23 * c26 - c22 * c27 * Math.cos(c29));
			var c33:Number = (c22 * c26) + (c23 * c27 * Math.cos(c29));
			var c35:Number = Math.sqrt(c31) / c33;
			var c36:Number = Math.atan(c35);
			var c38:Number = 0;
			if (c31==0)
			{
				c38 = 0;
			}else{
				c38 = c23 * c27 * Math.sin(c29) / Math.sqrt(c31);
			}
			
			var c40:Number = 0;
			if ((Math.cos(Math.asin(c38)) * Math.cos(Math.asin(c38))) == 0)
			{
				c40 = 0;
			}else{
				c40 = c33 - 2 * c22 * c26 / (Math.cos(Math.asin(c38)) * Math.cos(Math.asin(c38)));
			}
			
			var c41:Number = Math.cos(Math.asin(c38)) * Math.cos(Math.asin(c38)) * (c15 * c15 - c16 * c16) / (c16 * c16);
			var c43:Number = 1 + c41 / 16384 * (4096 + c41 * (-768 + c41 * (320 - 175 * c41)));
			var c45:Number = c41 / 1024 * (256 + c41 * (-128 + c41 * (74 - 47 * c41)));
			var c47:Number = c45 * Math.sqrt(c31) * (c40 + c45 / 4 * (c33 * (-1 + 2 * c40 * c40) - c45 / 6 * c40 * (-3 + 4 * c31) * (-3 + 4 * c40 * c40)));
			var c50:Number = c17 / 16 * Math.cos(Math.asin(c38)) * Math.cos(Math.asin(c38)) * (4 + c17 * (4 - 3 * Math.cos(Math.asin(c38)) * Math.cos(Math.asin(c38))));
			var c52:Number = c18 + (1 - c50) * c17 * c38 * (Math.acos(c33) + c50 * Math.sin(Math.acos(c33)) * (c40 + c50 * c33 * (-1 + 2 * c40 * c40)));
			
			var c54:Number = c16 * c43 * (Math.atan(c35) - c47);
			
			c54 = c54 / 1000;	// unit of km 
			// return distance in meter
			return c54;
		}
		
		
		/**
		 * 생성자
		 */
		public function GPS()
		{
		}
	}
}